home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 5167 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.6 KB  |  57 lines

  1. Path: news.th-darmstadt.de!news!enno
  2. From: enno@inferenzsysteme.informatik.th-darmstadt.de (Enno Sandner)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Beginner: How to #include
  5. Date: 02 Feb 1996 19:33:16 GMT
  6. Organization: Fachbereich Informatik, TH Darmstadt
  7. Distribution: world
  8. Message-ID: <ENNO.96Feb2203316@kitz.inferenzsysteme.informatik.th-darmstadt.de>
  9. References: <west.32.008AC8C0@emt.e-technik.tu-muenchen.de>
  10. NNTP-Posting-Host: kitz.intellektik.informatik.th-darmstadt.de
  11. In-reply-to: west@emt.e-technik.tu-muenchen.de's message of Tue, 30 Jan 1996 18:32:06 UNDEFINED
  12.  
  13. In article <west.32.008AC8C0@emt.e-technik.tu-muenchen.de> west@emt.e-technik.tu-muenchen.de (Robert Westendorp) writes:
  14.  
  15.    Hi there, 
  16.  
  17.    following problem with hierarchical including:
  18.  
  19.    my_data.h:
  20.  
  21.    #include "picture.h"
  22.  
  23.    class A 
  24.    {
  25.    ..
  26.     CPicture m_picture;
  27.  
  28.    ..
  29.    }
  30.  
  31.    my_program.cpp:
  32.    #INCLUDE "PICTURE.H"
  33.    #include "my_data.h"
  34.  
  35.    program code...
  36.  
  37.    How can I avoid to include PICTURE.H in all of my files using
  38.    class A from my_data.prg?
  39.    There are lots of my_programm.cpp and a couple of my_data.h(s)!
  40.  
  41. The preprocessor offers the a way to avoid multiple inclusion of header-files.
  42. For example the 'picture.h' file may look like:
  43.  
  44. picture.h:
  45. #ifndef picture_h
  46. #define picture_h
  47. ...
  48. #endif
  49.  
  50. When 'picture.h' is visited the first time the macro 'picture_h' is defined
  51. and the subsequent code '...' is included. The next time 'picture_h' is already
  52. defined and neither the macro is redefined nor the code is included.
  53. Take a look at your favorite system header-files. They are usually all wrapped
  54. in conditionals.
  55.  
  56.         Enno
  57.